<?php 

class Controller extends Smarty
{
    // 访问不存在的方法时触发
    public function __call($fun,$params)
    {
        header("HTTP/1.0 404not found");
        echo '控制器 404 NOT FOUND';
        exit;
    }

    // 初始化
    public function __construct()
    {
        // 实例化模板
        // $smarty = new Smarty();
        // var_dump($smarty);

        //初始化配置 
        $this->setTemplateDir('./views')
               ->setCompileDir('./runtime/view_c')
               ->setConfigDir('./configs')
               ->setCacheDir('./runtime/caches');

        // 配置缓存
        $this->caching = CACHING;
        $this->cache_lifetime = CACHE_LIFETIME;
    }

    // 跳转重定向
    public function redirect($message, $url = null)
    {
        echo "<script>alert('{$message}');</script>";
        if (empty($url)) {
            echo "<script>history.go(-1)</script>";
        } else {
            echo "<script>location.href='{$url}'</script>";
        }
    }
}